﻿@{
    <div id="KpiAsDataTd" style="text-align: center; width: @ViewBag.TdWidth; height: 583px;">
        @{
            System.Data.DataTable kpiAsData = ViewBag.KpiAsData;
            System.Data.DataTable kpiAsDataGroup = ViewBag.KpiAsDataGroup;
            string vb_month = ViewBag.Month;
            if (kpiAsDataGroup.Rows.Count > 0)
            {
                <table style="width: 100%;">
                    <thead style="position:sticky;top:0;">
                        <tr style="background-color:#507cd1; font-size:18px; color: white; font-weight:bold; height:40px;">
                            <td hidden="hidden">IS_UPDATE</td>
                            <td hidden="hidden">KPI_ID</td>
                            <td width="60"><input id="kpiastitlecheck" type="checkbox" aria-label="kpiastitlecheck" onchange="kpititelcheckChangeAs(event)" /></td>
                            <td width="80">域</td>
                            <td width="60">年度</td>
                            <td width="60">NO</td>
                            <td width="160">流程</td>
                            <td width="180">績效指標</td>
                            <td width="180">公式</td>
                            <td width="120">分子/分母</td>
                            <td width="80">衡量頻率</td>
                            <td width="100">數據<br />詳細來源</td>
                            <td width="200">數據<br />抓取步驟</td>
                            <td width="80">聯絡人</td>
                            <td width="100">數據<br />抓取時間</td>
                            <td width="80">輸入<br />方式</td>
                            <td width="80">流程<br />負責人</td>
                            @{
                                //月份篩選
                                if (vb_month == "1")
                                {
                                    <td width="110">上年度<br />12月</td>
                                }
                                for (int i = 1; i <= 12; i++)
                                {
                                    if (vb_month.IndexOf(',') >= 0 && !vb_month.Split(',').Contains(i.ToString()))
                                    {
                                        //多選
                                        continue;
                                    }
                                    else
                                    {
                                        //單選
                                        if (!vb_month.Split(',').Contains((i + 1).ToString()) && !vb_month.Split(',').Contains(i.ToString()) && vb_month != "0")
                                        {
                                            continue;
                                        }
                                    }
                                    if (vb_month.Split(',').Count() > 2)
                                    {
                                        <td width="100">@(i)月</td>
                                    }
                                    else
                                    {
                                        <td width="110">@(i)月</td>
                                    }
                                }
                            }
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            int colorIndex = 1;
                            string color;
                            System.Data.DataRow[] dataRows;
                            foreach (System.Data.DataRow item in kpiAsDataGroup.Rows)
                            {
                                color = colorIndex % 2 == 1 ? "#eff3fb" : "#ffffff";
                                <tr style="background-color:@color; height:50px;">
                                    <td hidden="hidden">N</td>
                                    <td hidden="hidden">@item["KPI_ID"].ToString()</td>
                                    <td><input class="kpiasdatacheck" type="checkbox" aria-label="kpiasdatacheck" onchange="kpidatacheckChangeAs(event)" /></td>
                                    <td>@item["SITE"].ToString()</td>
                                    <td>@item["KPI_YEAR"].ToString()</td>
                                    <td>@item["KPI_NO"].ToString()</td>
                                    <td>@item["KPI_DESC"].ToString()</td>
                                    <td>@item["KPI_TARGET"].ToString()</td>
                                    <td>@item["KPI_FUNC"].ToString()</td>
                                    <td>@item["KPI_VALUE_DESC"].ToString()</td>
                                    <td>@item["FREQ_DESC"].ToString()</td>
                                    <td>@item["DATA_SOURCE"].ToString()</td>
                                    <td>@item["DATA_SOURCE_DESC"].ToString()</td>
                                    <td>@item["CONTACT_PERSON"].ToString()</td>
                                    <td>@item["WHEN_TO_GET_DESC"].ToString()</td>
                                    <td>@item["INPUT_TYPE"].ToString()</td>
                                    <td>@item["KPI_OWNER"].ToString()</td>
                                    @{

                                        dataRows = kpiAsData.Select("KPI_ID=" + item["KPI_ID"].ToString() + " AND SITE='" + item["SITE"].ToString() + "' AND KPI_YEAR=" + item["KPI_YEAR"].ToString() + " AND KPI_NO=" + item["KPI_NO"].ToString() + " AND PERIOD_TYPE='" + item["PERIOD_TYPE"].ToString() + "' AND KPI_VALUE_TYPE = '" + item["KPI_VALUE_TYPE"].ToString() + "'");
                                        for (int i = 1; i <= dataRows.Count(); i++)
                                        {
                                            if (vb_month.IndexOf(',') >= 0 && !vb_month.Split(',').Contains(i.ToString()))
                                            {
                                                //多選
                                                continue;
                                            }
                                            else
                                            {
                                                //單選
                                                if (!vb_month.Split(',').Contains((i + 1).ToString()) && !vb_month.Split(',').Contains(i.ToString()) && vb_month != "0")
                                                {
                                                    continue;
                                                }
                                            }
                                            <td>@dataRows[i - 1]["KPI_VALUE"].ToString()</td>
                                        }
                                    }
                                    <td></td>
                                    <td></td>
                                </tr>
                                colorIndex++;
                            }
                        }
                    </tbody>
                    <tfoot>
                        <tr style="background-color:#507cd1; font-size:15px; color: white; height:35px;">
                            <td colspan="17" style="text-align: left; position: sticky; bottom: 0; left: 0; z-index: 2; background-color: #507cd1;">
                                &#12288;&#12288;&#12288;
                                第:
                                <span id="pagesIndex">@ViewBag.PagesIndex</span>
                                頁/共:
                                <span>@ViewBag.PagesCount</span>
                                頁
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClickAs('FP')">首頁</a>
                                <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClickAs('PP')">上一頁</a>
                                <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClickAs('NP')">下一頁</a>
                                <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClickAs('LP')">尾頁</a>
                                轉到第
                                <input id="pagesTo" type="number" value="@ViewBag.PagesIndex" style="height:20px;width:40px;color:black;" />
                                頁
                                <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClickAs('TP')">Go</a>
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                                每頁
                                <select id="pagesNum" style="height: 20px; width: 40px; color: black;" onchange="btnKpiSearchClickAs('FP')">
                                    @{
                                        int value = 0;
                                        for (int i = 1; i <= 5; i++)
                                        {
                                            value = i * 10;
                                            if (ViewBag.pagesNum == i * 10)
                                            {
                                                <option value="@value" selected="selected">@value</option>
                                            }
                                            else
                                            {
                                                <option value="@value">@value</option>
                                            }
                                        }
                                    }
                                </select>
                                筆/共
                                <span>@ViewBag.DataNums</span>
                                筆
                            </td>
                        </tr>
                    </tfoot>
                </table>
            }
            else
            {
                <h3>未查詢到數據！</h3>
            }
        }
    </div>
}